package com.o2o.filter;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;

public class ExtendStrutsFilter extends StrutsPrepareAndExecuteFilter {
	@Override
    public void doFilter(ServletRequest req, ServletResponse res,FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        //不过滤的url,可以不断添加,如fck可用/fckeditor/editor/filemanager/connectors/fileupload,下面的是flex
//        System.out.println("getRequestURI:"+request.getRequestURI());
        Pattern p = Pattern.compile("^.*?\\.jsp.*$");
        Matcher m = p.matcher(request.getRequestURI());
        if (m.matches()) {
            //System.out.println("使用自定义的过滤器");
            chain.doFilter(req, res);
        }else{
            //System.out.println("使用默认的过滤器");
            super.doFilter(req, res, chain);
        }
    }
}
